'''
@Project ：hdcms-scripts
@File    ：create_live.py
@IDE     ：PyCharm
@Author  ：朱广杰
@Date    ：2024/11/11 18:07
'''
import json

import jsonpath

from script.api.base_api import BaseCmsv2Api
from common.time_util import get_current_datetime, get_next_current_datetime, get_now_timestamp
from common.FILE_PATH import load_yaml_file, BASE_DIR


#  导入课程
class CopyCourseInfoApi(BaseCmsv2Api):
    def __init__(self):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/copy_course_info'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "course_id": "42260883dddf50be17a8312764248c33",
            "sku_mode": "yxs",
            "tob_remark": ""
        }

# 获取最新创建的课程ID
class GetCourseIdApi(BaseCmsv2Api):
    def __init__(self):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/get_course_list'
        self.method = 'get'
        self.params = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "course_qs": "",
            "course_id": "",
            "sku_mode": "yxs",
            "teacher_qs": "",
            "page_no": 0
        }


# 编辑课程内容为上线的直播课
class UpdateCourseApi(BaseCmsv2Api):
    def __init__(self, course_id: str, course_name: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/update_course'
        self.method = 'post'
        self.json = {
            "course_id": course_id,
            "course_meta": {
                "title": course_name,
                "sku_mode": "yxs",
                "category": "",
                "course_type": 0,
                "live_type": 0,
                "course_score": 5,
                "last_weight_sum": 0,
                "common_can_see": 0,
                "rank": 0,
                "status": 1,
                "school_time": get_current_datetime(),
                "end_time": get_next_current_datetime(),
                "course_note_status": 0,
                "allow_money_buy": 1,
                "money_price": 128,
                "allow_yanzhi_buy": 0,
                "yanzhi_price": 0,
                "recommended_language": "",
                "purchase_url": "",
                "keywords": "",
                "intro_sentence": "",
                "cover_image_pingan": "",
                "language": 0,
                "switch_course": {},
                "course_introduce": "【直面创业真命题，双十一创业者节为创业者赋能】\n\n在这个充满挑战与机遇并存的时代，创业者，依旧是推动社会进步和经济增长的重要力量。作为新时代最具创新精神的群体，他们在市场的波动中前行，在不断的自我突破中寻找属于自己的机会。\n\n为了帮助更多的创业者在不确定的市场环境中找到方向，\n混沌 APP 将在2024年11月2日至11月12日，\n推出为期11天的「双十一创业者节」，\n回应这一群体最关心的市场趋势与创业命题。\n\n本次「双十一创业者节」，以“直面创业真命题”为主题，带来深度解析、案例分享和资源对接，从市场现状、新技术、新人群、到新场景，为创业者们提供了一系列深入的探讨和实践案例，助力创业者在复杂的经济环境中突破自我。\n\n创业从来不是一件简单的事，但每一位敢于直面挑战的创业者，都值得我们致敬。\n我们期待与每一位创业者共同前行，见证你们的伟大时刻。",
                "course_introduce_extend": [
                    {
                        "content": "9:00-9:30 主题分享\n《TikTok的竞争格局和红利机会》\n\n9:35-10:35 创业者圆桌探索流\n《如何抓住TikTok红利实现一盘货卖全球？》\n\n10:35-11:10 互动问答\n\n11:10-12:00 双十一直播间特别活动",
                        "extend_id": "",
                        "title": "课程重点",
                        "images": [
                            {
                                "url": "https://yxs-web.oss-cn-beijing.aliyuncs.com/85720d2594109ad2832b68a8bc9032dc.jpeg?_hd_scale=0.58&_hd_height_scale=33.3333",
                                "scale": 0.58
                            },
                            {
                                "url": "https://yxs-web.oss-cn-beijing.aliyuncs.com/81b7d588f72b95b17825153777ee7224.png?_hd_scale=0.5539143279172821&_hd_height_scale=30.0889",
                                "scale": 0.5539143279172821
                            },
                            {
                                "url": "https://yxs-web.oss-cn-beijing.aliyuncs.com/968b74028bf0cf4c20f50b6360700065.jpeg?_hd_scale=0.58&_hd_height_scale=33.3333",
                                "scale": 0.58
                            }
                        ]
                    }
                ],
                "lt_watch_range": 1,
                "cover_image": "https://yxs-web.oss-cn-beijing.aliyuncs.com/330667d15c58448511a2c14f33432c1e.png",
                "cover_image_v2": "https://yxs-web.oss-cn-beijing.aliyuncs.com/34ae1fec12d97a5a4287cdbe8ddc6f42.png",
                "cover_image_2x1": "https://yxs-web.oss-cn-beijing.aliyuncs.com/08b1b78414160bc880b0c2984e354534.png",
                "cover_image_1x2": "https://yxs-web.oss-cn-beijing.aliyuncs.com/c3c2cc416340390c6df22b5d4d1785d4.png",
                "cover_image_h5": "https://yxs-web.oss-cn-beijing.aliyuncs.com/3554b48e00d7105a5682c5857942e3a9.png",
                "share_info": {
                    "share_h5_switch": 1,
                    "title": "邀你免费学《{课程标题}》",
                    "sub_title": "{老师名}，{老师职位}",
                    "thumbnail": "https://yxs-web.oss-cn-beijing.aliyuncs.com/3a11606e962781b9f48bf936fb07c54b.png?_hd_scale=0.9747292418772563&_hd_height_scale=12.3111",
                    "wxshare_title_sku_member": "{用户名}邀请你，一起来混沌学园听{老师名}老师的课",
                    "poster_img_list": [
                        "https://yxs-web.oss-cn-beijing.aliyuncs.com/1f500e7591a7b03073f4e0e09f87b418.jpeg",
                        "https://yxs-web.oss-cn-beijing.aliyuncs.com/46e24c64f734ea8b382375164087bedc.png"
                    ]
                },
                "relate_courses": [
                    {
                        "module_name": "",
                        "course_ids": []
                    }
                ],
                "wxshare_title_sku_member": "{用户名}邀请你，一起来混沌学园听{老师名}老师的课",
                "share_h5_switch": 1
            },
            "course_resource": {
                "id": "",
                "source_type": "course",
                "android_image": "",
                "android_url": "",
                "ios_image": "",
                "ios_url": ""
            },
            "teacher_list": [
                {
                    "teacher_id": "b3fa8567b984b751f2fc4b4d1e788fef",
                    "teacher_name": "测试老师3",
                    "name": "测试老师3",
                    "course_num": 39,
                    "position": "职位",
                    "head_image": "https://yxs-web.oss-cn-beijing.aliyuncs.com/3a11606e962781b9f48bf936fb07c54b.png?_hd_scale=0.9747292418772563&_hd_height_scale=12.3111",
                    "_index": 0,
                    "_rowKey": 26
                }
            ],
            "course_theme_id": "",
            "course_task_id": "",
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun"
        }


#  修改直播配置
class UpdateLiveInfoApi(BaseCmsv2Api):
    def __init__(self, course_id: str, live_state: int=2, preside_user_id: str='374a2b4762b7938337af9ddec0a3218a'):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/edit_live_config_info'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "live_state": live_state,
            "prevue_path": "",
            "is_display_ask": 0,
            "free_trial_duration": 300,
            "free_trial_content": "",
            "live_exit_toast": 1,
            "ask_question_switch": 1,
            "course_live_type": 1,
            "preside_live_obj": {
                "whiteboard_trtc_user_id": "mf_whiteboard_user_id",
                "preside_ready_status": 1,
                "preside_user_info": {
                    "user_id": "374a2b4762b7938337af9ddec0a3218a",
                    "head_img": "https://yxs-web.oss-cn-beijing.aliyuncs.com/1718095292992..jpg",
                    "user_name": "马化腾"
                },
                "preside_live_stream_url": "mf_0315ce63e0820c2525757a81f3cb88fb_133433",
                "room_id": 133433,
                "live_stream_user_id": "__df_lsru_4eac54a61d270b5adfccb2dbd197246c",
                "stream_address_obj": {
                    "video_ch_url": "mf_0315ce63e0820c2525757a81f3cb88fb_133433"
                }
            },
            "is_open_stake": 0,
            "live_start_time": "",
            "dm_sync_time": "",
            "is_flowhouse_demo": 1,
            "allow_preside_close": 1,
            "course_id": course_id,
            "preside_user_id": preside_user_id
        }

#  修改探索流配置
class UpdateFlowHouseInfoApi(BaseCmsv2Api):
    def __init__(self, course_id: str, wish_type: int=3):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/course/edit_flowhouse_info'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "course_id": course_id,
            "conference_obj": {
                "conference_mode_is": 0,
                "conference_url": ""
            },
            "flowhouse_obj": {
                "flowhouse_form_id": 0,
                "flowhouse_wish_type": wish_type,
                "flowhouse_tip_is": 1,
                "wish_user_cnt": 0,
                "flowhouse_tag_allocate_mode_is": 0,
                "flowhouse_mode_is": 1,
                "flowhouse_desc_list": [
                    "022年11月，ChatGPT的推出不仅标志着智能革命新纪元的到来，更显露了人工智能（AI）从科幻走向现实，"
                    "成为重塑我们生活和工作方式的强劲力量。2023年GPT-4的亮相，以及GPT系列产品的持续革新，让我们亲眼目睹了AI速度和能力的惊人飞跃。"
                    "现在，通用人工智能（AGI）的曙光已在地平线上闪现，虽未完全成形，却似乎触手可及。这不仅预示着技术的飞跃，更预兆着对人类社会结构和认知方式的根本革新。"
                    "科学家们对通用人工智能（AGI）的到来提出了各种预测，其中一些观点预测这一转折点可能在2029年到来。另外，所谓的“技术奇点”——那个机器智能超越全部人类智能的时刻，"
                    "有预测认为可能在2045年左右出现。这两个预期时刻分别代表着AI能力的重要发展阶段，以及一个更加深远的未来场景。在这个未来场景中，AI的进步可能带来根本性的、不可逆转的巨大变革。"
                    "深度学习之父Geoffrey Hinton将脑科学的原理应用于开发类人脑工作方式的算法，收获巨大成功。他对人工神经网络的深刻洞见与坚持，源自于他的心理学背景和对人类大脑的深度理解。"
                    "同样地，本堂课中，刘嘉教授作为一位在心理学、脑科学与人工智能交汇处深"
                ]
            }
        }

# 获取同问列表
class GetAskListoApi(BaseCmsv2Api):
    def __init__(self, course_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/follow_ask/get_ask_data'
        self.method = 'get'
        self.params = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "course_id": course_id
        }

# 开启课程同问
class OpenAskApi(BaseCmsv2Api):
    def __init__(self, course_id: str, teacher_id: str, state: int):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/follow_ask/set_ask_valid'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "state": state,
            "teacher_id": teacher_id,
            "course_id": course_id
        }

# 设置赞赏
class SetRewardApi(BaseCmsv2Api):
    def __init__(self, course_id: str, state: int):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/reward/set_course_reward'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "teachers_info": [
                {
                    "teacher_name": "测试老师3",
                    "teacher_id": "b3fa8567b984b751f2fc4b4d1e788fef",
                    "state": state,
                    "sequence": 0,
                    "prize_list": [
                         {"content": "", "abstract": "10", "start_limit": 1, "end_limit": 100, "title": ""}
                     ]
                 }
            ],
            "course_id": course_id
        }


# 设置直播间主会场
class SetMainRoomApi(BaseCmsv2Api):
    def __init__(self, course_id: str):
        super().__init__()
        self.common = load_yaml_file('/config/common.yml')
        self.url = f'{self.host}/goapi/sub_venue_course/edit'
        self.method = 'post'
        self.json = {
            "token": self.common['token'],
            "admin_id": self.common['admin_id'],
            "timestamp": get_now_timestamp(),
            "_ignore_sign": "_hundun",
            "course_id": course_id,
            "sub_course_cover_img": "https://yxs-web.oss-cn-beijing.aliyuncs.com/989b6803604b1c1e0681e55b9d0311ce.png?_hd_scale=0.7567567567567568&_hd_height_scale=4.9333",
            "sub_course_id": course_id,
            "sub_course_title": "脚本创建直播课",
            "is_owner": 1
        }
if __name__ == '__main__':
    # cci_resp = CopyCourseInfoApi().send()
    # gci_resp = GetCourseIdApi().send()
    # course_id = jsonpath.jsonpath(gci_resp.json(), '$..course_id')[0]
    # course_name = jsonpath.jsonpath(gci_resp.json(), '$..course_title')[0]
    # uc_resp = UpdateCourseApi(course_id='').send()
    # uli_resp = UpdateLiveInfoApi(course_id='').send()
    resp = GetAskListoApi(course_id='5502f4576d69db6e24bc609be38ea3c7').send()
    teacher_id = jsonpath.jsonpath(resp.json(), '$..teacher_id')[0]
    OpenAskApi(course_id='5502f4576d69db6e24bc609be38ea3c7', teacher_id=teacher_id, state=1).send()
    SetMainRoomApi(course_id='5502f4576d69db6e24bc609be38ea3c7').send()



